/**
 * org.vz.product.collect.maintain.service.impl
 * @since : jdk 1.8
 */
package org.vz.product.collect.maintain.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.vz.product.collect.maintain.dao.GetNamesDao;
import org.vz.product.collect.maintain.dao.GetServiceByIdDao;
import org.vz.product.collect.maintain.dao.ServiceVisualMonitoringDao;
import org.vz.product.collect.maintain.domain.GetAllServiceEntity;
import org.vz.product.collect.maintain.domain.GetNames;
import org.vz.product.collect.maintain.domain.ServiceExceptionsEntity;
import org.vz.product.collect.maintain.domain.entity.GetServiceResult;
import org.vz.product.collect.maintain.domain.entity.GetServiceResult.Services;
import org.vz.product.collect.maintain.service.ServiceVisualMonitoringService;

/**
 * @author Morik is Yongxu.Wang 服务可视化监控
 * @CreateTime 2017年10月16日 15:55:03
 * @version 1.0.0
 * @description TODO
 */
@Service
public class ServiceVisualMonitoringServiceImpl implements
		ServiceVisualMonitoringService {
	@Autowired
	ServiceVisualMonitoringDao serviceVisualMonitoringDao;
	@Autowired
	GetServiceByIdDao getServiceByIdDao;
	@Autowired
	GetNamesDao getNamesDao;
	@Autowired
	GetServiceByIdAndDayServiceImpl GetServiceByIdAndDayService;

	GetServiceResult getServiceResult;

	@Override
	public GetServiceResult getAllServiceByDay(String starTime, String endTime,
			int type) {
		getServiceResult = new GetServiceResult();
		Map<String, String> pr = new HashMap<String, String>();
		pr.put("starTime", starTime);
		pr.put("endTime", endTime);
		List<ServiceExceptionsEntity> count = serviceVisualMonitoringDao
				.getSQLManager().select("messagelog.getExceputions",
						ServiceExceptionsEntity.class, pr);

		List<GetAllServiceEntity> service = serviceVisualMonitoringDao
				.getSQLManager().select("messagelog.getAllService",
						GetAllServiceEntity.class, pr);

		getServiceResult.serviceCount = service.size();
		if (count.size() > 0) {
			getServiceResult.exceptionCount = count.get(0).getNumber();
		} else {
			getServiceResult.exceptionCount = 0;
		}

		List<GetNames> names = getNamesDao.getSQLManager().select(
				"messagelog.getName", GetNames.class);
		
		for (GetAllServiceEntity s : service) {
            
			Services ss = GetServiceByIdAndDayService.getService(starTime,
					endTime, s.serviceName, type);
			
			for(GetNames name:names){
            	if(s.serviceName.equals(name.getEnglishName())){
            		ss.servicesName=name.getChaName();
            	}
            }
			getServiceResult.myServices.add(ss);
		}
		getServiceResult.serviceCount = getServiceResult.myServices.size();
		if (getServiceResult != null) {
			getServiceResult.msg = "查询成功";
			getServiceResult.status = 1;
		}
		return getServiceResult;
	}

}
